﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Vanfa.Entities.User;

namespace Vanfa.Web
{
    public partial class WebMaster : System.Web.UI.MasterPage
    {
        /// <summary>
        /// 是否显示登录框
        /// </summary>
        private bool IsShowLoginBox
        {
            get
            {
                return !String.IsNullOrEmpty(Request.QueryString["returl"]);
            }
        }

        /// <summary>
        /// 登录以后跳转的URL
        /// </summary>
        private string ReturnURL
        {
            get
            {
                var url = Request.QueryString["returl"];
                return url ?? Server.UrlDecode(url);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.InitForm();
            if (!Page.IsPostBack)
            {
                var t = Session["user"] as vUserTicket;
                var isLogined = t != null;
                plNoLogin.Visible = !isLogined;
                plLogined.Visible = isLogined;
                lUserName.Text = isLogined ? t.UserName : "";
            }
        }

        /// <summary>
        /// 初始化模版页信息
        /// </summary>
        private void InitForm()
        {
            phLoginBox.Visible = IsShowLoginBox;
            hdReturnUrl.Value = ReturnURL;
        }
    }
}